<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>短信验证</title>
    <meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/css/public.css">
    <%- include('../_global/baseLibs') %>
    <script src="/static/js/crypto-js.js"></script>

    <style>
        .messageBox p{
            width: 94%;
            margin: 1rem auto;
            padding: 1rem 0.5rem;
            border: 1px solid #ddd;
            border-radius: 10px;
        }
        .getyzm{
            margin-left:10px;
        }
        .yzm{
            height: 3rem;
            width: 30%;
            float: left;
            line-height: 3rem;
        }
        .inputyzm{
            display: block;
            width: 30%;
            height: 3rem;
            border-radius: 5px;
            float: left;
        }
        .sendyzm{
            display: block;
            height: 3rem;
            border-radius: 5px;
            float: right;
            margin-right: 10px;
            width: 30%;
            color:#fff;
        }
        .submitYZM{
            border-radius: 5px;
            display: block;
            background: #0db9ff;
            width: 94%;
            margin: 10rem auto 0;
            color:#fff;
            padding: 1rem 0;
        }
        .blue{
            background: #0db9ff;
            color:#fff;
        }
        .gray{
            color:#fff;
            background: #ddd;
        }
    </style>

</head>

<body>
<!-- header start -->
<header id="header" class="header-box grey fixed">
    <div class="header-content">
        <div class="left-tool">
            <a class="back" href="javascript:void(0)"><i class="iconfont icon-back"></i></a>
        </div>
        <div class="title">短信验证</div>
    </div>
</header>
<!-- header end -->
<div class="messageBox">
    <p>查询到您在家人列表里本人的手机号码为:
        <span class="userphone"></span>,
        如您确认该手机号码为您本人所有，请点击“获取验证码”。收到验证码后填入下面的输入框，点击“提交”完成二次验证。
    </p>
    <div class="getyzm">
        <div class="yzm">验证码:</div>
        <input type="text" class="inputyzm">
        <button class="sendyzm blue" id="sendyzm">获取验证码</button>
    </div>
    <input type="button"  value="提交" class="submitYZM">
</div>
</body>
<script>


    var page_dxyz = (function($, page_dxyz) {
        var userInfo = StoreCache.getCache("jkcsUserInfo");
        var userphone=userInfo.phoneNum;
        var key = "jkcs";

        var sendButton=$(".sendyzm")
        var wait=61,timeOut;

        var cfg_def = {
            time: time,
            timeMins: timeMins,
            sendYZM: sendYZM,
            encryptionStr: encryptionStr,
        }

        page_dxyz.init = function(cfg){
            $.extend(page_dxyz, cfg_def, cfg);
            $(".userphone").text(userphone);
            //发送验证码
            $("#sendyzm").on("click",function (e) {
                e.preventDefault();
                var _this=$(this);
                page_dxyz.time(_this);
            })
            //提交验证码
            $(".submitYZM").on("click",function () {
//        var read="read";
//        StoreCache.setCache("readMZTK",read);
//        console.log(StoreCache.getCache("readMZTK"));
//        var patientCardId = userInfo["patientCardId"];
//        var idCard = encryptionStr(key, patientCardId);x
//        var url="/html/jkda/index.html?idCard=" + idCard + "&key=" + key;
//        var options = {url: url, title: "个人健康",animate:"pop"};
//        $.QuickUrlUtils.redirectJSBridge(options);
                var userInfo = StoreCache.getCache("jkcsUserInfo");
                var userphone=userInfo.phoneNum;
                var inputyzm=$(".inputyzm").val();
                var backyzm=StoreCache.getCache("yzm");
                var read="read";
                if($(".inputyzm").val()==backyzm){
                    StoreCache.setCache("readMZTK",read);
                    StoreCache.setCache("thisPhone",userphone);
                    var patientCardId = userInfo["patientCardId"];
                    var idCard = page_dxyz.encryptionStr(key, patientCardId);
                    var url="/html/jkda/index.html?idCard=" + idCard + "&key=" + key;
                    var options = {url:url, title: "个人健康",animate:"push"};
                    $.QuickUrlUtils.redirectJSBridge(options);
                    StoreCache.setCache("readTK","read");

                }
                else {
                    $.QuickAlert.alertNormal("请输入正确的验证码!");
                }

            })

        }

        return page_dxyz;


        function time(o) {
            page_dxyz.timeMins(o);
            $.QuickRemote.AjaxJson("/api/jkcsHt/hzxx/sendMassage", page_dxyz.sendYZM,{phone: userphone});
        }

        //时间倒计时
        function timeMins(o) {
            if (wait == 1) {
                sendButton.html("获取短信验证码");
                sendButton.removeClass("gray").addClass("blue");
                clearTimeout(timeOut);
                sendButton.attr("disabled",false);
                wait = 61;
            } else {
                wait--;
                timeOut = setTimeout(function () {
                    page_dxyz.timeMins();
                }, 1000);
                sendButton.html(wait + "s");
                sendButton.attr("disabled",true);
                sendButton.removeClass("blue").addClass("gray");
            }

        }

        function sendYZM(res) {
            sendButton.attr("disabled",false);
            sendButton.attr("onclick","");
            var yzm=res;
            StoreCache.setCache("yzm",yzm);
        }

        function encryptionStr(key, plaintText){
            key = CryptoJS.enc.Utf8.parse(key);
            var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            });
            var encryptedStr = encryptedData.ciphertext.toString();
            return encryptedStr;
        }
    })(jQuery, {});
    
</script>
</html>